home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap02 / howto05 / drwsutl2.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-03-05  |  65.0 KB  |  1,735 lines

  1. unit Drwsutl2;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ShellAPI, FileCtrl, DRWSUtl1;
  8.  
  9. const
  10.   EOC_CHANGEDIR = 1;  { Error Operation Code for change directory failure }
  11.   EOC_SOURCECOPY = 2; { Error Operation Code for source copy failure      }
  12.   EOC_DESTCOPY = 3;   { Error Operation Code for destination copy failure }
  13.   EOC_DELETEFILE = 4; { Error Operation Code for file delete failure      }
  14.   EOC_DELETEDIR = 5;  { Error Operation Code for directory delete failure }
  15.   EOC_RENAMEFILE = 6; { Error Operation Code for renaming failure         }
  16.   EOC_MAKEDIR = 7;    { Error Operation Code for MkDir failure            }
  17.   EOC_SETATTR = 8;    { Error Operation Code for Set Attributes failure   }
  18.  
  19.   FAC_COPY = 1;       { File Action Code for recursive copying            }
  20.   FAC_MOVE = 2;       { File Action Code for recursive moving             }
  21.   FAC_DELETE = 3;     { File Action Code for recursive deletion           }
  22. type
  23.   { This is a descendant of TFileListbox }
  24.   { Which puts icons of files into the   }
  25.   { Objects array rather than the stand- }
  26.   { ard bitmaps.                         }
  27.   TIconFileListBox = class( TFileListBox )
  28.   public
  29.     { public methods and data }
  30.     function GetNextSelection( SourceDirectory : String;
  31.               var CurrentItem : Integer ) : String;
  32.   end;
  33.   TFileWorkBench = class( TComponent )
  34.   public
  35.     GlobalError        : Integer;  { This is used by FMXUCopyFile for er code }
  36.     GlobalErrorType    : Integer;  { This holds the Operation code            }
  37.     function ForceTrailingBackSlash( const TheFileName : String ) : String;
  38.     function StripNonRootTrailingBackSlash(
  39.               const TheFileName : String ) : String;
  40.     procedure GetFileAttributes( TheFile : String; var IsDirectory , IsArchive ,
  41.                 IsVolumeID , IsHidden , IsReadOnly , IsSysFile : Boolean );
  42.     procedure HandleIOException( TheOpCode : Integer; ThePath : String;
  43.                                  TheMessage : String; TheCode : Integer );
  44.     procedure HandleDOSError( TheOpCode : Integer; ThePath : String;
  45.                 TheCode : Integer );
  46.     procedure FMXUCopyFile(const FileName, DestName: String);
  47.     function CopyFile( TargetPath ,
  48.                DestinationPath : String ) : Boolean;
  49.     procedure ChangeTheDirectory( NewPath : String );
  50.     procedure ChangeTheDriveAndDirectory( NewDrive : Integer );
  51.     procedure CopyTheFile( OldPath , NewPath : String );
  52.     procedure MoveTheFile( OldPath , NewPath : String );
  53.     procedure DeleteTheFile( ThePath : String );
  54.     procedure RenameTheFile( OldPath , NewName : String );
  55.     procedure CreateNewDirectory( NewPath : String );
  56.     procedure RemoveDirectory( ThePath : String );
  57.   end;
  58.   TFileIconPanel = class( TPanel )
  59.   private
  60.     { Private declarations }
  61.     FHighlightColor : TColor;                 { This holds bright edge bevel }
  62.     FShadowColor    : TColor;                 { This holds dark edge bevel   }
  63.     procedure TheClick( Sender : TObject );   { This holds override click    }
  64.     procedure TheDblClick( Sender : TObject );{ This holds override dblclick }
  65.   protected                                   { event method procedure.      }
  66.     { Protected declarations }
  67.     procedure Paint; override;                { This allows custom painting  }
  68.   public
  69.     { Public declarations }
  70.     FTheIcon : TIcon;                         { This is the display icon    }
  71.     FTheName : String;                        { This is the filename        }
  72.     FTheLabel : TLabel;                       { This is the display label   }
  73.     Selected : Boolean;                       { This holds selection status }
  74.     constructor Create(AOwner : TComponent); override; { override create    }
  75.     procedure Initialize( PanelX              ,             { Left          }
  76.                           PanelY              ,             { Top           }
  77.                           PanelWidth          ,             { Width         }
  78.                           PanelHeight         ,             { Height        }
  79.                           PanelBevelWidth     ,             { Bevel Width   }
  80.                           LabelFontSize         : Integer;  { Font size     }
  81.                           PanelColor          ,             { Main color    }
  82.                           PanelHighlightColor ,             { Bright color  }
  83.                           PanelShadowColor    ,             { Dark color    }
  84.                           LabelTextColor        : TColor;   { Text color    }
  85.                           TheFilename         ,             { Filename      }
  86.                           LabelFontName         : String;   { Font name     }
  87.                           LabelFontStyle        : TFontStyles;  { Font style}
  88.                           ExtraData             : Integer       );  { Drive }
  89.     destructor Destroy; override;             { override destroy to free    }
  90.   end;
  91.   TFileIconPanelScrollBox = class( TScrollBox )
  92.   public
  93.     { Public methods and data }
  94.     TheFWB              : TFileWorkBench; { Used for file manipulation         }
  95.     IconsNeedRefreshing : Boolean;                   { Flag to redo display    }
  96.     TheIconSize        : Integer;   { Holds Individual Icon size               }
  97.     TheIconSpacing     : Integer;   { Holds total icon footprint               }
  98.     MaxIconsInARow     : Integer;   { Set for screen size.                     }
  99.     TheStoredHandle    : HWnd;
  100.     procedure Update;                                { Called to reset display }
  101.     constructor Create( AOwner : TComponent ); override;  { Override inherited }
  102.     procedure ClearTheFIPs;                          { Clears the FIPs safely  }
  103.     procedure AddDriveIcons( var XCounter , YCounter : Integer ); { Add drives }
  104.     procedure GetColorsForFileIcon( TheFile : String;
  105.                var BC , HC , SC , TC : TColor );
  106.     procedure GetIconsForEntireDirectory( TargetPath  : String );
  107.     function GetNextSelection( SourceDirectory : String;
  108.               var CurrentItem : Integer ) : String;
  109.     procedure DisplayRecursiveSearchResults(
  110.       TheStartingDirectory : String );
  111.   end;
  112.  
  113.   { This procedure gets an icon for a file using FindExecutable  }
  114.   { and ExtractIcon. (assumes file/dir is passed)                }
  115.   procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  116.   { This procedure spaces out the bitbtn components on a tpanel }
  117.   procedure SpacePanelButtons( WhichPanel : TPanel );
  118.  
  119. implementation
  120. {$R DRWSUTL2.RES}                 { Import custom resource file }
  121.  
  122. { This procedure spaces out the bitbtn components on a tpanel }
  123. procedure SpacePanelButtons( WhichPanel : TPanel );
  124. var TheCalculatedSpacing     ,            { Holds primary spacing }
  125.     TheFullCalculatedSpacing   : Integer; { Holds full spacing    }
  126.     Counter_1                  : Integer; { Loop counter          }
  127.     TotalIBs                   : Integer; { Gets total buttons    }
  128. begin
  129.   { Set up spacing values }
  130.   TotalIBs := WhichPanel.ControlCount;
  131.   TheCalculatedSpacing := (( WhichPanel.Width - 6 - ( TotalIbs * 49 ))
  132.    div ( TotalIbs + 1 ));
  133.   TheFullCalculatedSpacing := TheCalculatedSpacing + 49;
  134.   { Loop through all imported buttons and set their Left values }
  135.   for Counter_1 := 1 to WhichPanel.ControlCount do
  136.   begin
  137.     if Counter_1 = 1 then
  138.     begin
  139.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  140.        TheCalculatedSpacing;
  141.     end
  142.     else
  143.     begin
  144.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  145.        (( Counter_1 - 1 ) * TheFullCalculatedSpacing ) + TheCalculatedSpacing;
  146.     end;
  147.   end;
  148. end;
  149.  
  150. { This procedure gets an icon for a file using FindExecutable  }
  151. { and ExtractIcon. (assumes file/dir is passed)                }
  152. procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  153. var TheExt           : String; { File extension holder }
  154.     TheOtherPChar  ,           { Windows ASCIIZ string }
  155.     ThePChar         : PChar;  { Windows ASCIIZ string }
  156.     Dummy : Word;
  157. begin
  158.   { Check for directory and if so get directory icon from RES file }
  159.   if (( FileGetAttr( TheName ) and faDirectory ) = faDirectory ) then
  160.   begin
  161.     { Set up the PChar to communicate with Windows }
  162.     GetMem( TheOtherPChar , 255 );
  163.     { Convert Pascal-style string to ASCIIZ Pchar }
  164.     StrPCopy( TheOtherPChar , 'DIRECTORY' );
  165.     { Use API call to return icon handle of Icon Resource in FILECTRL.RES }
  166.     TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  167.     { Release memory from PChar }
  168.     FreeMem( TheOtherPChar , 255 );
  169.     { Leave }
  170.     exit;
  171.   end;
  172.   { Assume archive file; get its extension }
  173.   TheExt := Uppercase( ExtractFileExt( TheName ));
  174.   { If not an executable/image file then use FindExecutable to get icon }
  175.   if (( TheExt <> '.EXE' ) and ( TheExt <> '.BAT' ) and
  176.       ( TheExt <> '.PIF' ) and ( TheExt <> '.COM' )) then
  177.   begin
  178.     { Grab three chunks of memory }
  179.     GetMem( ThePChar , 255 );
  180.     { Set up the name and its directory in Windows string formats }
  181.     StrPCopy( ThePChar, TheName );
  182.     Dummy := 65535;
  183.     {**** Windows 95 Specialized call ****** }
  184.     TheIcon.Handle := ExtractAssociatedIcon( hInstance , ThePChar , Dummy );
  185.     if TheIcon.Handle = 0 then
  186.     begin
  187.       GetMem( TheOtherPChar , 255 );
  188.       StrPCopy( TheOtherPChar , 'NOICON' );
  189.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  190.       FreeMem( TheOtherPChar , 255 );
  191.       exit;
  192.     end;
  193.     FreeMem( ThePChar , 255 );
  194.   end
  195.   else
  196.   { Assume Windows Executable file, so get icon from it with ExtractIcon API }
  197.   begin
  198.     GetMem( ThePChar , 255 );
  199.     StrPCopy( ThePChar , TheName );
  200.     { Try to get first icon for file }
  201.     Dummy := 65535;
  202.     TheIcon.Handle := ExtractAssociatedIcon( hInstance , ThePChar , Dummy );
  203.     FreeMem( ThePChar , 255 );
  204.     { If handle is 0 invalid icon format so use default from RES file }
  205.     if TheIcon.Handle = 0 then
  206.     begin
  207.       GetMem( TheOtherPChar , 255 );
  208.       StrPCopy( TheOtherPChar , 'NOICON' );
  209.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  210.       FreeMem( TheOtherPChar , 255 );
  211.       exit;
  212.     end;
  213.   end;
  214. end;
  215.  
  216. { This procedure does a fully error-trapped change directory }
  217. procedure TFileWorkBench.ChangeTheDirectory( NewPath : String );
  218. var CurrentDirectory : String;
  219. begin
  220.   if NewPath = '..' then
  221.   begin { Back up one level }
  222.     {$I+}
  223.     try
  224.       { Find the current directory }
  225.       GetDir( 0 , CurrentDirectory );
  226.       { Use EFP to move up one level }
  227.       CurrentDirectory := ExtractFilePath( CurrentDirectory );
  228.       { Strip trailing \ if not root }
  229.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  230.       { Try the change to the new drive }
  231.       ChDir( CurrentDirectory );
  232.     except
  233.       { if any exception occurs instantiate exception and show }
  234.       On E:EInOutError do
  235.       begin
  236.         { Call custom error display/lookup procedure }
  237.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  238.          E.Message , E.ErrorCode );
  239.       end;
  240.     end;
  241.   end
  242.   else
  243.   begin { Change to explicit path }
  244.     {$I+}
  245.     try
  246.       { Get target directory path }
  247.       CurrentDirectory := NewPath;
  248.       { Strip trailing \ if not root }
  249.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  250.       { Try the change to the new drive }
  251.       ChDir( CurrentDirectory );
  252.     except
  253.       { if any exception occurs instantiate exception and show }
  254.       On E:EInOutError do
  255.       begin
  256.         { Call custom error display/lookup procedure }
  257.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  258.          E.Message , E.ErrorCode );
  259.       end;
  260.     end;
  261.   end;
  262. end;
  263.  
  264. { This procedure does a fully error-trapped change directory }
  265. procedure TFileWorkBench.ChangeTheDriveAndDirectory( NewDrive : Integer );
  266. var CurrentDirectory : String;
  267. begin
  268.   {$I+}
  269.   try
  270.     { Find the working directory on new drive }
  271.     GetDir( NewDrive , CurrentDirectory );
  272.     { Try the change to the new drive }
  273.     ChDir( CurrentDirectory );
  274.   except
  275.     { if any exception occurs instantiate exception and show }
  276.     On E:EInOutError do
  277.     begin
  278.       { Call custom error display/lookup procedure }
  279.       HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  280.        E.Message , E.ErrorCode );
  281.     end;
  282.   end;
  283. end;
  284.  
  285. { This procedure copies a single file with error trapping }
  286. procedure TFileWorkBench.CopyTheFile( OldPath , NewPath : String );
  287. var AResult : Boolean; { Internal data flag }
  288. begin
  289.   { If Copyfile returns false an error occurred }
  290.   AResult := CopyFile( OldPath , NewPath +
  291.    ExtractFileName( OldPath ));
  292.   { Display meaningful error message }
  293.   if not AResult then HandleDOSError( GlobalErrorType ,
  294.    ExtractFileName( OldPath ) , GlobalError );
  295. end;
  296.  
  297. { This procedure moves a file by copying and delete it }
  298. procedure TFileWorkBench.MoveTheFile( OldPath , NewPath : String );
  299. var AResult : Boolean; { Internal data flag }
  300.     TheFile : File;    { Use to get errors  }
  301. begin
  302.   { If Copyfile returns false an error occurred }
  303.   AResult := CopyFile( OldPath , NewPath +
  304.     ExtractFileName( OldPath ));
  305.   { Display meaningful error message }
  306.   if not AResult then HandleDOSError( GlobalErrorType ,
  307.    ExtractFileName( OldPath ), GlobalError );
  308.   { After valid copying, delete source file }
  309.   {$I+}
  310.   if AResult then try
  311.     { Use this trick to get valid exception handling }
  312.     AssignFile( TheFile , OldPath );
  313.     { Use erase because Deletefile doesn't give exceptions! }
  314.     Erase( TheFile );
  315.   except
  316.     { if any exception occurs instantiate exception and show }
  317.     On E:EInOutError do
  318.     begin
  319.       { Call custom error display/lookup procedure }
  320.       HandleIOException( EOC_DELETEFILE , ExtractFileName( OldPath ) ,
  321.        E.Message , E.ErrorCode );
  322.     end;
  323.   end;
  324. end;
  325.  
  326. { This procedure safely deletes a single file }
  327. procedure TFileWorkBench.DeleteTheFile( ThePath : String );
  328. var TheFile : File; { Internal file handle }
  329. begin
  330.   {$I+}
  331.   try
  332.     { Use this trick to get valid exception handling }
  333.     AssignFile( TheFile , ThePath );
  334.     { Use erase because Deletefile doesn't give exceptions! }
  335.     Erase( TheFile );
  336.   except
  337.     { if any exception occurs instantiate exception and show }
  338.     On E:EInOutError do
  339.     begin
  340.       { Call custom error display/lookup procedure }
  341.       HandleIOException( EOC_DELETEFILE , ExtractFileName( ThePath ) ,
  342.        E.Message , E.ErrorCode );
  343.     end;
  344.   end;
  345. end;
  346.  
  347. { This procedure renames a file with full error trapping }
  348. procedure TFileWorkBench.RenameTheFile( OldPath , NewName : String );
  349. var TheFile : File; { Internal file handle }
  350. begin
  351.   {$I+}
  352.   try
  353.     { Use this trick to get valid exception handling }
  354.     AssignFile( TheFile , OldPath );
  355.     { Use this because RenameFile doesn't give exceptions! }
  356.     Rename( TheFile , NewName );
  357.   except
  358.     { if any exception occurs instantiate exception and show }
  359.     On E:EInOutError do
  360.     begin
  361.       { Call custom error display/lookup procedure }
  362.       HandleIOException( EOC_RENAMEFILE , ExtractFileName( OldPath ) ,
  363.        E.Message , E.ErrorCode );
  364.     end;
  365.   end;
  366. end;
  367.  
  368. { This procedure creates a new directory with full error trapping }
  369. procedure TFileWorkBench.CreateNewDirectory( NewPath : String );
  370. begin
  371.   {$I+}
  372.   try
  373.     Mkdir( NewPath );
  374.   except
  375.     { if any exception occurs instantiate exception and show }
  376.     On E:EInOutError do
  377.     begin
  378.       { Call custom error display/lookup procedure }
  379.       HandleIOException( EOC_MAKEDIR , ExtractFileName( NewPath ) ,
  380.        E.Message , E.ErrorCode );
  381.     end;
  382.   end;
  383. end;
  384.  
  385. { This procedure remove a directory with full error trapping }
  386. procedure TFileWorkBench.RemoveDirectory( ThePath : String );
  387. begin
  388.   {$I+}
  389.   try
  390.     Rmdir( ThePath );
  391.   except
  392.     { if any exception occurs instantiate exception and show }
  393.     On E:EInOutError do
  394.     begin
  395.       { Call custom error display/lookup procedure }
  396.       HandleIOException( EOC_DELETEDIR , ExtractFileName( ThePath ) ,
  397.        E.Message , E.ErrorCode );
  398.     end;
  399.   end;
  400. end;
  401.  
  402. { This is a generic copy routine taken from Delphi sample code }
  403. { It has been edited to return viable error codes!             }
  404. procedure TFileWorkBench.FMXUCopyFile(const FileName, DestName: String);
  405. var
  406.   CopyBuffer: Pointer; { buffer for copying }
  407.   BytesCopied: Longint;
  408.   TheAttr : Integer;
  409.   Source, Dest: Integer; { handles }
  410. const
  411.   ChunkSize: Longint = 8192; { copy in 8K chunks }
  412. begin
  413.   GetMem(CopyBuffer, ChunkSize); { allocate the buffer }
  414.   Source := FileOpen(FileName, fmShareDenyWrite); { open source file }
  415.   if Source < 0 then
  416.   begin  { error creating source file }
  417.     GlobalErrorType := EOC_SOURCECOPY;
  418.     GlobalError := -IOResult;
  419.     if GlobalError = 0 then GlobalError := -157;
  420.     FreeMem( CopyBuffer, ChunkSize );
  421.     exit;
  422.   end;
  423.   Dest := FileCreate(DestName); { create output file; overwrite existing }
  424.   if Dest < 0 then
  425.   begin  { error creating destination file }
  426.     FileClose( Source );
  427.     GlobalErrorType := EOC_DESTCOPY;
  428.     GlobalError := -IOResult;
  429.     if GlobalError = 0 then GlobalError := -159;
  430.     FreeMem( CopyBuffer , ChunkSize );
  431.     exit;
  432.   end;
  433.   {$I-}
  434.   repeat
  435.     BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize); { read chunk}
  436.     if BytesCopied > 0 then { if we read anything... }
  437.     FileWrite(Dest, CopyBuffer^, BytesCopied); { ...write chunk }
  438.   until BytesCopied < ChunkSize; { until we run out of chunks }
  439.   {$I+}
  440.   GlobalError := -IOResult;  { get any error code which happens during copying }
  441.   FileClose(Dest); { close the destination file }
  442.   FileClose(Source); { close the source file }
  443.   FreeMem(CopyBuffer, ChunkSize); { free the buffer }
  444. end;
  445.  
  446. { This function calls the sample Copy code and handles errors }
  447. function TFileWorkBench.CopyFile( TargetPath ,
  448.           DestinationPath : String ) : Boolean;
  449. begin
  450.   { Set global error value to no error }
  451.   GlobalError := 0;
  452.   { Call the sample procedure to do the copy }
  453.   FMXUCopyFile( TargetPath, DestinationPath );
  454.   { If no error return true else return false }
  455.   if GlobalError < 0 then CopyFile := false else
  456.    CopyFile := true;
  457. end;
  458.  
  459. { This procedure handles displaying a user-friendly Dialog box with a }
  460. { Message for Delphi IO exception errors.                             }
  461. procedure TFileWorkBench.HandleIOException( TheOpCode : Integer;
  462.            ThePath : String; TheMessage : String; TheCode : Integer );
  463. var ErrorMessageString : String;  { Holds internal data }
  464.     OperationString    : String;  { Holds internal data }
  465. begin
  466.   { clear to check for unrecognized code }
  467.   ErrorMessageString := '';
  468.   { Check against imported code }
  469.   case TheCode of
  470.     2    : ErrorMessageString := 'File not found';
  471.     3    : ErrorMessageString := 'Path not found';
  472.     4    : ErrorMessageString := 'Too many open files';
  473.     5    : ErrorMessageString := 'File access denied';
  474.     6    : ErrorMessageString := 'Invalid file handle';
  475.     12    : ErrorMessageString := 'Invalid file access code';
  476.     15    : ErrorMessageString := 'Invalid drive number';
  477.     16  : ErrorMessageString := 'Cannot remove current directory';
  478.     17    : ErrorMessageString := 'Cannot rename across drives';
  479.     100    : ErrorMessageString := 'Disk read error';
  480.     101    : ErrorMessageString := 'Disk write error';
  481.     102    : ErrorMessageString := 'File not assigned';
  482.     103    : ErrorMessageString := 'File not open';
  483.     104    : ErrorMessageString := 'File not open for input';
  484.     105    : ErrorMessageString := 'File not open for output';
  485.   end;
  486.   case TheOpCode of
  487.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  488.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  489.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  490.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  491.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  492.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  493.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  494.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  495.   end;
  496.   { If not recognized use message; not a DOS error; reset cursor for neatness }
  497.   if ErrorMessageString = '' then
  498.   begin
  499.     Screen.Cursor := crDefault;
  500.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  501.      TheMessage , mtError , [mbOK],0);
  502.   end
  503.   else
  504.   begin
  505.     { Recognized DOS exception, reset cursor for neatness }
  506.     Screen.Cursor := crDefault;
  507.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  508.      ErrorMessageString , mtError , [mbOK], 0 );
  509.   end;
  510. end;
  511.  
  512. { This procedure handles displaying a user-friendly Dialog box with a }
  513. { Message for DOS error codes.                                        }
  514. procedure TFileWorkBench.HandleDOSError( TheOpCode : Integer;
  515.            ThePath : String;  TheCode : Integer );
  516. var ErrorMessageString : String;  { internal message holder }
  517.     OperationString : String;     { internal message holder }
  518. begin
  519.   { clear the message holder to check for unrecognized code }
  520.   ErrorMessageString := '';
  521.   { Negate the code back to normal number and check to set string }
  522.   case -TheCode of
  523.     2    : ErrorMessageString := 'File not found';
  524.     3    : ErrorMessageString := 'Path not found';
  525.     4    : ErrorMessageString := 'Too many open files';
  526.     5    : ErrorMessageString := 'File access denied';
  527.     6    : ErrorMessageString := 'Invalid file handle';
  528.     12    : ErrorMessageString := 'Invalid file access code';
  529.     15    : ErrorMessageString := 'Invalid drive number';
  530.     16  : ErrorMessageString := 'Cannot remove current directory';
  531.     17    : ErrorMessageString := 'Cannot rename across drives';
  532.     100    : ErrorMessageString := 'Disk read error';
  533.     101    : ErrorMessageString := 'Disk write error';
  534.     102    : ErrorMessageString := 'File not assigned';
  535.     103    : ErrorMessageString := 'File not open';
  536.     104    : ErrorMessageString := 'File not open for input';
  537.     105    : ErrorMessageString := 'File not open for output';
  538.     157 : ErrormessageString := 'Could not open Source File';
  539.     159 : ErrormessageString := 'Could not open Target File';
  540.   end;
  541.   case TheOpCode of
  542.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  543.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  544.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  545.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  546.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  547.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  548.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  549.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  550.   end;
  551.   { If the string is empty an unrecognized code was sent in }
  552.   if ErrorMessageString = '' then
  553.   begin
  554.     { Sent up db based on source or target error; reset cursor for neatness }
  555.     Screen.Cursor := crDefault;
  556.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' Error Code: ' +
  557.      IntToStr( TheCode ) , mtError , [mbOK],0);
  558.   end
  559.   else  { Code is recognized, use message from case statement }
  560.   begin
  561.     { Format the output for source or target error }
  562.     Screen.Cursor := crDefault;
  563.     MessageDlg( OperationString + ExtractFilePath( ThePath ) + ' ' +
  564.      ErrorMessageString , mtError , [mbOK], 0 );
  565.   end;
  566. end;
  567.  
  568. { This procedure sets the imported booleans to the file's attributes }
  569. procedure TFileWorkBench.GetFileAttributes( TheFile : String; var IsDirectory ,
  570.            IsArchive , IsVolumeID , IsHidden , IsReadOnly ,
  571.             IsSysFile : Boolean );
  572. var TheResult : Integer; { Traps for error code on VolumeID }
  573. begin
  574.   { Clear the imported flags for default }
  575.   IsDirectory := false;
  576.   IsArchive := false;
  577.   IsVolumeID := false;
  578.   IsHidden := False;
  579.   IsReadOnly := false;
  580.   IsSysFile := false;
  581.   { Make the Dos call }
  582.   TheResult := FileGetAttr( TheFile );
  583.   if TheResult < 0 then
  584.   begin
  585.     { Volume ID returns -2 (?) }
  586.     IsVolumeID := true;
  587.     { It has no other properties }
  588.     exit;
  589.   end;
  590.   { Use AND test to set all other properties }
  591.   if (( TheResult and faDirectory ) = faDirectory ) then IsDirectory := true;
  592.   if (( TheResult and faArchive ) = faArchive ) then IsArchive := true;
  593.   if (( TheResult and faVolumeID ) = faVolumeID ) then IsVolumeID := true;
  594.   if (( TheResult and faReadOnly ) = faReadOnly ) then IsReadOnly := true;
  595.   if (( TheResult and faHidden ) = faHidden ) then IsHidden := true;
  596.   if (( TheResult and faSysFile ) = faSysFile ) then IsSysFile := true;
  597. end;
  598.  
  599. { This function makes sure a pathname has a trailing \ }
  600. function TFileWorkBench.ForceTrailingBackSlash(
  601.           const TheFileName : String ) : String;
  602. var TempString : String;  { Used to hold function result }
  603. begin
  604.   { If no trailing \ add one (root will already have one.) }
  605.   if TheFileName[ Length( TheFileName ) ] <> '\' then
  606.    TempString := TheFileName + '\' else TempString := TheFileName;
  607.   { Return modified or non-modified string }
  608.   ForceTrailingBackslash := TempString;
  609. end;
  610.  
  611. { This function makes sure a non-root dir has no trailing \ }
  612. function TFileWorkBench.StripNonRootTrailingBackSlash(
  613.           const TheFileName : String ) : String;
  614. var TempString : String ; { Used to hold function result }
  615. begin
  616.   { Default is no change }
  617.   TempString := TheFileName;
  618.   { If not root then }
  619.   if Length( TheFileName ) > 3 then
  620.   begin
  621.     { If has a trailing backslash remove it }
  622.     if TheFileName[ Length( TheFileName )] = '\' then
  623.     begin
  624.       TempString := Copy( TheFileName , 1 ,
  625.        Length( TheFileName ) - 1 );
  626.     end;
  627.   end;
  628.   { Export the final result }
  629.   StripNonRootTrailingBackSlash := TempString;
  630. end;
  631.  
  632. { This gets the next selected listbox item }
  633. function TIconFileListBox.GetNextSelection( SourceDirectory : String;
  634.           var CurrentItem : Integer ): String;
  635. var TheResult : String;  { Internal storage }
  636.     finished  : boolean; { Loop flag        }
  637. begin
  638.   { If out of items to check signal and exit }
  639.   if CurrentItem > Items.Count then TheResult := '' else
  640.   begin
  641.     { Otherwise scan from current position till match or end }
  642.     finished := false;
  643.     while not finished do
  644.     begin
  645.       { Check against selected property }
  646.       if Selected[ CurrentItem - 1 ] then
  647.       begin
  648.         { If selected then return it and abort loop }
  649.         TheResult := SourceDirectory + Items[ CurrentItem - 1 ];
  650.         finished := true;
  651.         { Increment current position }
  652.         CurrentItem := CurrentItem + 1;
  653.      end
  654.       else
  655.       begin
  656.         { Increment current position }
  657.         CurrentItem := CurrentItem + 1;
  658.         { Otherwise check for end of data and abort if out of entries }
  659.         if CurrentItem > Items.Count then
  660.         begin
  661.           TheResult := '';
  662.           finished := true;
  663.         end;
  664.       end;
  665.     end;
  666.   end;
  667.   { Return stored result }
  668.   GetNextSelection := TheResult;
  669. end;
  670.  
  671. { Create method for FIP                                }
  672. constructor TFileIconPanel.Create( AOwner : TComponent );
  673. begin
  674.   { call inherited -- VITAL! }
  675.   inherited Create( AOwner );
  676.   { create icon and label components, making self owner/displayer }
  677.   FTheIcon := TIcon.Create;
  678.   FTheLabel := TLabel.Create( Self );
  679.   FThelabel.Parent := Self;
  680.   { Set own and labels mouse methods to stored methods }
  681.   OnClick := TheClick;
  682.   OnDblClick := TheDblClick;
  683.   FTheLabel.OnClick := TheClick;
  684.   FTheLabel.OnDblClick := TheDblClick;
  685.   { Set alignment and autosize properties of the label }
  686.   FTheLabel.Autosize := false;
  687.   FTheLabel.Alignment := taCenter;
  688.   { Set selected to false }
  689.   Selected := false;
  690. end;
  691.  
  692. { Initialization method for FIP                                         }
  693. procedure TFileIconPanel.Initialize( PanelX              ,
  694.                                      PanelY              ,
  695.                                      PanelWidth          ,
  696.                                      PanelHeight         ,
  697.                                      PanelBevelWidth     ,
  698.                                      LabelFontSize         : Integer;
  699.                                      PanelColor          ,
  700.                                      PanelHighlightColor ,
  701.                                      PanelShadowColor    ,
  702.                                      LabelTextColor        : TColor;
  703.                                      TheFilename         ,
  704.                                      LabelFontName         : String;
  705.                                      LabelFontStyle        : TFontStyles;
  706.                                      ExtraData             : Integer );
  707.  
  708. var TheLabelHeight ,             { Holder for label pixel height }
  709.     TheLabelWidth    : Integer;  { Holder for label pixel width  }
  710.     TheOtherPChar    : PChar;    { Windows ASCIIZ string         }
  711. begin
  712.   { Set the basic properties based on imported parameters }
  713.   Left := PanelX;
  714.   Top := PanelY;
  715.   Width := PanelWidth;
  716.   Height := PanelHeight;
  717.   Color := PanelColor;
  718.   BevelWidth := PanelBevelWidth;
  719.   FHighlightColor := PanelHighlightColor;
  720.   FShadowColor := PanelShadowColor;
  721.   FTheName := TheFilename;
  722.   { If the ExtraData field is non-0 then a drive is being sent in }
  723.   if ExtraData <> 0 then
  724.   begin
  725.     { Use the data field value to determine which icon to get from RES file }
  726.     case ExtraData of
  727.       1 : begin
  728.             GetMem( TheOtherPChar , 255 );
  729.             StrPCopy( TheOtherPChar , 'FLOPPY35' );
  730.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  731.             FreeMem( TheOtherPChar , 255 );
  732.           end;
  733.       2 : begin
  734.             GetMem( TheOtherPChar , 255 );
  735.             StrPCopy( TheOtherPChar , 'FIXEDHD' );
  736.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  737.             FreeMem( TheOtherPChar , 255 );
  738.           end;
  739.       3 : begin
  740.             GetMem( TheOtherPChar , 255 );
  741.             StrPCopy( TheOtherPChar , 'NETWORKHD' );
  742.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  743.             FreeMem( TheOtherPChar , 255 );
  744.           end;
  745.       4 : begin
  746.             GetMem( TheOtherPChar , 255 );
  747.             StrPCopy( TheOtherPChar , 'CDROM' );
  748.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  749.             FreeMem( TheOtherPChar , 255 );
  750.           end;
  751.       5 : begin
  752.             GetMem( TheOtherPChar , 255 );
  753.             StrPCopy( TheOtherPChar , 'RAM' );
  754.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  755.             FreeMem( TheOtherPChar , 255 );
  756.           end;
  757.     end;
  758.     { The FileNme property is already set up for the caption; use directly }
  759.     FTheLabel.Caption := TheFilename;
  760.     { Set up the hint for later use (make sure to set ShowHint) }
  761.     Hint := 'Change to ' + TheFileName;
  762.     ShowHint := true;
  763.     { Set up all imported label properties and center it for drawing }
  764.     with FTheLabel do
  765.     begin
  766.       Font.Name := LabelFontName;
  767.       Font.Size := LabelFontSize;
  768.       Font.Style := LabelFontStyle;
  769.       Font.Color := LabelTextColor;
  770.       Canvas.Brush.Color := PanelColor;
  771.       Canvas.Font := Font;
  772.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  773.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  774.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  775.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  776.       Top := Top + Round( Self.Height * 0.75 );
  777.       Height := TheLabelHeight;
  778.       Width := TheLabelWidth;
  779.     end;
  780.   end
  781.   else
  782.   begin
  783.     { A file or directory has been sent in; use GetIconForFile to obtain an }
  784.     { icon either from the file, its owner, or a RES file default.          }
  785.     GetIconForFile( FTheName , FTheIcon );
  786.     { Check for the Backup caption and set it specially }
  787.     if ExtractfileName( FThename ) = '..' then
  788.     begin
  789.       FTheLabel.Caption := '..';
  790.       Hint := 'Up One Level';
  791.     end
  792.     else
  793.     begin
  794.       { Otherwise just get the filename for the label caption }
  795.       { And the full path for the hint (used later.)          }
  796.       FTheLabel.caption := ExtractFileName( UpperCase( FTheName ));
  797.       Hint := FTheName;
  798.     end;
  799.     { Activate showhint so hints are seen }
  800.     ShowHint := true;
  801.     { Set label properties with imported values and center for display }
  802.     with FTheLabel do
  803.     begin
  804.       Font.Name := LabelFontName;
  805.       Font.Size := LabelFontSize;
  806.       Font.Style := LabelFontStyle;
  807.       Font.Color := LabelTextColor;
  808.       Canvas.Brush.Color := PanelColor;
  809.       Canvas.Font := Font;
  810.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  811.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  812.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  813.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  814.       Top := Top + Round( Self.Height * 0.75 );
  815.       Height := TheLabelHeight;
  816.       Width := TheLabelWidth;
  817.     end;
  818.   end;
  819. end;
  820.  
  821. { Destroy method for FIP }
  822. destructor TFileIconPanel.Destroy;
  823. begin
  824.   { free component resources }
  825.   FTheIcon.Free;
  826.   FTheLabel.Free;
  827.   { call inherited -- VITAL! }
  828.   inherited Destroy;
  829. end;
  830.  
  831. { TheClick method for FIP; used for event responses }
  832. procedure TFileIconPanel.TheClick( Sender : TObject );
  833. begin
  834.   { Currently ignore drive clicks }
  835.   if Pos( 'DRIVE' , FTheName ) > 0 then exit;
  836.   { Flip status of bevels }
  837.   if BevelOuter = bvRaised then BevelOuter := bvLowered else
  838.    BevelOuter := bvRaised;
  839.   { Flip selected variable }
  840.   Selected := not Selected;
  841.   { Set redisplay }
  842.   Invalidate;
  843. end;
  844.  
  845. { TheDblClick method for FIP; used for event responses }
  846. procedure TFileIconPanel.TheDblClick( Sender : TObject );
  847. var CurrentDirectory : String;    { Use to store dirs }
  848.     TheDrive         : String;    { Get drive letter  }
  849.     WhichDrive       : Integer;   { Get drive number  }
  850.     ErrorCheck       : Integer;
  851.     TheFWB           : TFileWorkBench;
  852. begin
  853.   { Create FileWorkBench for later use }
  854.   TheFWB := TFileWorkBench.Create( Self );
  855.   { Check for label or FIP sender }
  856.   if Sender is TFileIconPanel then
  857.   begin
  858.     if FTheLabel.Caption = '..' then
  859.     begin { deal with backup request }
  860.       { Change to new directory }
  861.       TheFWB.ChangeTheDirectory( '..' );
  862.       { Call special method due to SendMessage problem! }
  863.       TFileIconPanelScrollBox( Parent ).Update;
  864.     end
  865.     else
  866.     begin
  867.       { Check for DRIVE id in name }
  868.       if Pos( 'DRIVE' , FTheName ) <> 0 then
  869.       begin { Double Click on a Drive Icon }
  870.         { Pull out the letter from name }
  871.         TheDrive := Copy( FtheName , 7 , 1 );
  872.         { Convert it to a number }
  873.         WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  874.         TheFWB.ChangeTheDriveAndDirectory( WhichDrive );
  875.         { Call special method due to SendMessage problem! }
  876.         TFileIconPanelScrollBox( Parent ).Update;
  877.       end
  878.       else
  879.       begin { Double click on a dir/file icon }
  880.         if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  881.         begin { A directory, change to it }
  882.           { Since full path in name, simply change to it! }
  883.           TheFWB.ChangeTheDirectory( FTheName );
  884.           { Call special method due to SendMessage problem! }
  885.           TFileIconPanelScrollBox( Parent ).Update;
  886.         end
  887.         else
  888.         begin { A file; attempt to shellexecute it }
  889.           { Call shellexec as a wrapper around ShellExecute API call }
  890.           { False indicates failure, signal error                    }
  891.           if not ShellExec( FTheName , '' , '', false , SW_SHOWNORMAL , false )
  892.            then MessageDlg('Could not Shell out to ' + FTheName , mtError,
  893.             [mbOK], 0);
  894.         end;
  895.       end;
  896.     end;
  897.   end
  898.   else
  899.   begin
  900.     with Sender as TLabel do
  901.     begin
  902.       if Caption = '..' then
  903.       begin { Deal with backup request }
  904.         { Change to new directory }
  905.         TheFWB.ChangeTheDirectory( '..' );
  906.         { Call special method due to SendMessage problem! }
  907.         TFileIconPanelScrollBox( Parent ).Update;
  908.       end
  909.       else
  910.       begin
  911.         with Parent as TFileIconPanel do
  912.         begin
  913.           { Check for DRIVE id in name }
  914.           if Pos( 'DRIVE' , FTheName ) <> 0 then
  915.           begin { Double Click on a Drive Icon }
  916.             { Pull out the letter from name }
  917.             TheDrive := Copy( FtheName , 7 , 1 );
  918.             { Convert it to a number }
  919.             WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  920.             { Call the method to change to default dir on new drive }
  921.             TheFWB.ChangeTheDriveAndDirectory( WhichDrive );
  922.             { Call special method due to SendMessage problem! }
  923.             TFileIconPanelScrollBox( Parent ).Update;
  924.           end
  925.           else
  926.           begin { Double click on a dir/file icon }
  927.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  928.             begin { A directory, change to it }
  929.               { Since full path in name, simply change to it! }
  930.               TheFWB.ChangeTheDirectory( FTheName );
  931.               { Call special method due to SendMessage problem! }
  932.               TFileIconPanelScrollBox( Parent ).Update;
  933.             end
  934.             else
  935.             begin { A file; attempt to shellexecute it }
  936.               { Call shellexec as a wrapper around ShellExecute API call }
  937.               { False indicates failure, signal error                    }
  938.               if not ShellExec( FTheName , '' , '', false , SW_SHOWNORMAL ,
  939.                false ) then MessageDlg('Could not Shell out to ' + FTheName ,
  940.                 mtError, [mbOK], 0);
  941.             end;
  942.           end;
  943.         end;
  944.       end;
  945.     end;
  946.   end;
  947.   TheFWB.Free; { This prevents resource leak }
  948. end;
  949.  
  950. { Paint method for FIP; overrides normal paint }
  951. procedure TFileIconPanel.Paint;
  952. var
  953.   TheOtherRect   : TRect;   { Holds clientrect   }
  954.   TopColor     ,            { Holds bright color }
  955.   BottomColor    : TColor;  { Holds dark color   }
  956.  
  957. { These methods are from Borland Intl., copyright 1995 }
  958. procedure Frame3D(    Canvas       : TCanvas;
  959.                   var TheRect      : TRect;
  960.                       TopColor   ,
  961.                       BottomColor  : TColor;
  962.                       Width        : Integer );
  963.  
  964. procedure DoRect;
  965. var
  966.   TopRight, BottomLeft: TPoint;
  967. begin
  968.   with Canvas, TheRect do
  969.   begin
  970.     TopRight.X := Right;
  971.     TopRight.Y := Top;
  972.     BottomLeft.X := Left;
  973.     BottomLeft.Y := Bottom;
  974.     Pen.Color := TopColor;
  975.     PolyLine([BottomLeft, TopLeft, TopRight]);
  976.     Pen.Color := BottomColor;
  977.     Dec(BottomLeft.X);
  978.     PolyLine([TopRight, BottomRight, BottomLeft]);
  979.   end;
  980. end;
  981.  
  982. begin
  983.   Canvas.Pen.Width := 1;
  984.   Dec(TheRect.Bottom); Dec(TheRect.Right);
  985.   while Width > 0 do
  986.   begin
  987.     Dec(Width);
  988.     DoRect;
  989.     InflateRect(TheRect, -1, -1);
  990.   end;
  991.   Inc(TheRect.Bottom); Inc(TheRect.Right);
  992. end;
  993.  
  994. procedure AdjustColors(Bevel: TPanelBevel);
  995. begin
  996.   TopColor := FHighlightColor;
  997.   if Bevel = bvLowered then TopColor := FShadowColor;
  998.   BottomColor := FShadowColor;
  999.   if Bevel = bvLowered then BottomColor := FHighlightColor;
  1000. end;
  1001.  
  1002. { Custom code begins here }
  1003. begin
  1004.   { Get the rectangle of the control with API/method call }
  1005.   TheOtherRect := GetClientRect;
  1006.   { draw basic rectangle with basic color }
  1007.   with Canvas do
  1008.   begin
  1009.     Brush.Color := Color;
  1010.     FillRect(TheOtherRect);
  1011.   end;
  1012.   { Set up for top "icon" frame  and draw it with frame3d }
  1013.   TheOtherRect.Right := Width;
  1014.   TheOtherRect.Bottom := Round( Height * 0.75 ) - 6 ;
  1015.   if BevelOuter <> bvNone then
  1016.   begin
  1017.     AdjustColors(BevelOuter);
  1018.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1019.   end;
  1020.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  1021.   if BevelInner <> bvNone then
  1022.   begin
  1023.     AdjustColors(BevelInner);
  1024.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1025.   end;
  1026.   { Do the same for the lower "label" frame }
  1027.   TheOtherRect.Top := Round( Height * 0.75 ) - 5;
  1028.   TheOtherRect.Left := 0;
  1029.   TheOtherRect.Bottom := Height;
  1030.   TheOtherRect.Right := Width;
  1031.   if BevelOuter <> bvNone then
  1032.   begin
  1033.     AdjustColors(BevelOuter);
  1034.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1035.   end;
  1036.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  1037.   if BevelInner <> bvNone then
  1038.   begin
  1039.     AdjustColors(BevelInner);
  1040.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1041.   end;
  1042.   { Then draw the icon using canvas draw method }
  1043.   Canvas.Draw( (( Width - 32 ) div 2 ) + 1 ,
  1044.   ((( Round( Height * 0.75 ) - 6 ) - 32 ) div 2 ) + 1 , FTheIcon );
  1045. end;
  1046.  
  1047. { This procedure clears a scrollbox of all FileIconPanels }
  1048. procedure TFileIconPanelScrollbox.ClearTheFIPs;
  1049. var Counter_1 : Integer;
  1050.     TheComponent : TComponent;
  1051. begin
  1052.   { Note that must use while loop since component count continually }
  1053.   { decreases as removes are made!                                  }
  1054.   while ComponentCount > 0 do
  1055.   begin
  1056.     { Save the component as a generic TComponent }
  1057.     TheComponent := Components[ 0 ];
  1058.     { Call removecomponent to pull it out of the owner list for sb }
  1059.     { This avoids GPF when freeing the sb.                         }
  1060.     RemoveComponent( Components[ 0 ]);
  1061.     { Typecast the pointer and free it to release memory and res. }
  1062.     TFileIconPanel( TheComponent ).Free;
  1063.   end;
  1064. end;
  1065.  
  1066. { This procedure scans for drives and obtains their type and creates file }
  1067. { icon panels to represent them.                                          }
  1068. procedure TFileIconPanelScrollBox.AddDriveIcons( var XCounter ,
  1069.            YCounter : Integer );
  1070. type
  1071.   { This if from filectrl unit; reproduce here for completeness }
  1072.   TDriveType = (dtUnknown, dtNoDrive, dtFloppy, dtFixed, dtNetwork, dtCDROM,
  1073.                 dtRAM);
  1074. var
  1075.   DrivePC         : array[0..256] of char;
  1076.   DriveNum        : Integer;         { Used to get next drive via DOS fn   }
  1077.   IconType        : Integer;         { Used to hold icon type (defacto dt) }
  1078.   DriveChar       : Char;            { Used to hold drive letter           }
  1079.   DriveType       : TDriveType;      { Used for set-valued drive type      }
  1080.   Finished        : Boolean;         { Loop flag                           }
  1081.   TheFIP          : TFileIconPanel;  { Generic FileIconPanel variable      }
  1082.   ButtonColor   ,                    { Main panel color                    }
  1083.   ButtonHLColor ,                    { Bright panel color                  }
  1084.   ButtonSColor  ,                    { Dark panel color                    }
  1085.   Textcolor       : TColor;          { Label text color                    }
  1086.  
  1087. (*{ This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  1088. { Check whether drive is a CD-ROM.  Returns True if MSCDEX is installed }
  1089. {  and the drive is using a CD driver                                   }
  1090.  
  1091. function IsCDROM(DriveNum: Integer): Boolean; assembler;
  1092. asm
  1093.   MOV   AX,1500h { look for MSCDEX }
  1094.   XOR   BX,BX
  1095.   INT   2fh
  1096.   OR    BX,BX
  1097.   JZ    @Finish
  1098.   MOV   AX,150Bh { check for using CD driver }
  1099.   MOV   CX,DriveNum
  1100.   INT   2fh
  1101.   OR    AX,AX
  1102.   @Finish:
  1103. end;
  1104.  
  1105. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  1106. { Check whether drive is a RAM drive.                                   }
  1107. function IsRAMDrive(DriveNum: Integer): Boolean; assembler;
  1108. var
  1109.   TempResult: Boolean;
  1110. asm
  1111.   MOV   TempResult,False
  1112.   PUSH  DS
  1113.   MOV   BX,SS
  1114.   MOV   DS,BX
  1115.   SUB   SP,0200h
  1116.   MOV   BX,SP
  1117.   MOV   AX,DriveNum
  1118.   MOV   CX,1
  1119.   XOR   DX,DX
  1120.   INT   25h  { read boot sector }
  1121.   ADD   SP,2
  1122.   JC    @ItsNot
  1123.   MOV   BX,SP
  1124.   CMP   BYTE PTR SS:[BX+15h],0F8h  { reverify fixed disk }
  1125.   JNE   @ItsNot
  1126.   CMP   BYTE PTR SS:[BX+10h],1  { check for single FAT }
  1127.   JNE   @ItsNot
  1128.   MOV   TempResult,True
  1129.   @ItsNot:
  1130.   ADD   SP,0200h
  1131.   POP   DS
  1132.   MOV   AL, TempResult
  1133. end;
  1134.  
  1135. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  1136. { Finds the type of a drive letter.                                     }
  1137. function FindDriveType(DriveNum: Integer): TDriveType;
  1138. begin
  1139.   Result := TDriveType(GetDriveType(DriveNum));
  1140.   if (Result = dtFixed) or (Result = dtNetwork) then
  1141.   begin
  1142.     if IsCDROM(DriveNum) then Result := dtCDROM
  1143.     else if (Result = dtFixed) then
  1144.     begin
  1145.         { do not check for RAMDrive under Windows NT }
  1146.       if ((GetWinFlags and $4000) = 0) and IsRAMDrive(DriveNum) then
  1147.         Result := dtRAM;
  1148.     end;
  1149.   end;
  1150. end;*)
  1151.  
  1152. begin
  1153.   { Set the button colors to an aquamarine color scheme for drives }
  1154.   ButtonColor := clTeal;
  1155.   ButtonHLColor := clAqua;
  1156.   ButtonSColor := clNavy;
  1157.   TextColor := clblack;
  1158.   { Set initial variables before looping for all drives }
  1159.   finished := false;
  1160.   DriveNum := 0;
  1161.   while not finished do
  1162.   begin
  1163.     { Start with no drive found }
  1164.     IconType := 0;
  1165.     (*=============REMOVED DUE TO WINDOWS 95=========
  1166.     { Call the Borland method to get the drive info }
  1167.     DriveType := FindDriveType(DriveNum);
  1168.     ===============END WINDOWS 95 REMOVAL==========*)
  1169.     { Set its letter and make it uppercase }
  1170.     DriveChar := Chr(DriveNum + ord('a'));
  1171.     DriveChar := Upcase(DriveChar);
  1172.     StrPCopy( DrivePC , DriveChar + ':\' );
  1173.     {*&&&&&&&&&&&&&&&  WIN 95 CALL  &&&&&&&&&&&&&&&&&&&*}
  1174.     DriveType := TDriveType(GetDriveType( DrivePC ));
  1175.     { Assign an icon based on the drive type; if no drive exists type is nil }
  1176.     case DriveType of
  1177.       dtFloppy  : IconType := 1;
  1178.       dtFixed   : IconType := 2;
  1179.       dtNetwork : IconType := 3;
  1180.       dtCDROM   : IconType := 4;
  1181.       dtRAM     : IconType := 5;
  1182.     end;
  1183.     { Set to check next drive letter }
  1184.     DriveNum := DriveNum + 1;
  1185.     { But if no match then out of drives so set exit flag }
  1186.     if IconType = 0 then finished := true;
  1187.     { If drive was valid then set up the new FileIconPanel on the imported }
  1188.     { Scrollbox                                                            }
  1189.     if not finished then
  1190.     begin
  1191.       { Create the FileIconPanel and set its parent for memory mgmt and display}
  1192.       TheFIP := TFileIconPanel.Create( Self );
  1193.       TheFIP.Parent := Self;
  1194.       { Call its initialize method with imported position values and the   }
  1195.       { preset color scheme, a drive caption, and a minimum font. Note the }
  1196.       { setting of the ExtraData field to non-zero; this signals a drive   }
  1197.       { rather than a file being sent in.                                  }
  1198.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  1199.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  1200.         7 , ButtonColor, ButtonHLColor,
  1201.        ButtonSColor , TextColor , 'DRIVE ' + DriveChar + ':' , 'MS Serif' , [] ,
  1202.        IconType );
  1203.       { Increment the column counter; if it exceeds max move to new row      }
  1204.       { Note that these are 'var' parameters and will export final position. }
  1205.       XCounter := XCounter + 1;
  1206.       if XCounter > MaxIconsInARow then
  1207.       begin
  1208.         XCounter := 1;
  1209.         YCounter := YCounter + 1;
  1210.       end;
  1211.     end;
  1212.   end;
  1213. end;
  1214.  
  1215. { This procedure assigns colors to FIP's based on file attributes }
  1216. procedure TFileIconPanelScrollBox.GetColorsForFileIcon( TheFile : String;
  1217.            var BC , HC , SC , TC : TColor );
  1218. var AmADir      ,             { Booleans hold file attribs }
  1219.     AmAnArchive ,
  1220.     AmAVolumeId ,
  1221.     AmHidden    ,
  1222.     AmReadOnly  ,
  1223.     AmSystem      : Boolean;
  1224. begin
  1225.   { Make the call to internal fileworkbench to set attributes }
  1226.   TheFWB.GetFileAttributes( TheFile , AmADir , AmAnArchive , AmAVolumeId ,
  1227.    AmHidden , AmReadOnly , AmSystem );
  1228.   { Volume ID has no subtypes }
  1229.   if AmAVolumeID then
  1230.   begin
  1231.     BC := clOlive;
  1232.     HC := clYellow;
  1233.     SC := clBlack;
  1234.     TC := clWhite;
  1235.     exit;
  1236.   end;
  1237.   { Check all directory combinations }
  1238.   if AmADir then
  1239.   begin
  1240.     BC := clNavy;
  1241.     HC := clBlue;
  1242.     SC := clBlack;
  1243.     TC := clWhite;
  1244.     if AmHidden then
  1245.     begin
  1246.       if AmReadOnly then
  1247.       begin
  1248.         if AmSystem then
  1249.         begin { One HECK of a file! }
  1250.           BC := clBlack;
  1251.           HC := clSilver;
  1252.           SC := clGray;
  1253.           TC := clWhite;
  1254.         end
  1255.         else
  1256.         begin { Dir,RO,Hid }
  1257.           BC := clMaroon;
  1258.           HC := clFuchsia;
  1259.           SC := clGreen;
  1260.           TC := clWhite;
  1261.         end;
  1262.       end
  1263.       else
  1264.       begin { Dir,Hid }
  1265.         BC := clPurple;
  1266.         HC := clFuchsia;
  1267.         SC := clBlack;
  1268.         TC := clWhite;
  1269.       end;
  1270.     end
  1271.     else
  1272.     begin
  1273.       if AmReadOnly then
  1274.       begin
  1275.         if AmSystem then
  1276.         begin { Dir,RO,Sys }
  1277.           BC := clMaroon;
  1278.           HC := clLime;
  1279.           SC := clGreen;
  1280.           TC := clWhite;
  1281.         end
  1282.         else
  1283.         begin { Dir,RO }
  1284.           BC := clGreen;
  1285.           HC := clLime;
  1286.           SC := clBlack;
  1287.           TC := clWhite;
  1288.         end;
  1289.       end
  1290.       else
  1291.       begin
  1292.         if AmSystem then
  1293.         begin { Dir,Sys }
  1294.           BC := clMaroon;
  1295.           HC := clRed;
  1296.           SC := clBlack;
  1297.           TC := clWhite;
  1298.         end;
  1299.       end;
  1300.     end;
  1301.   end
  1302.   else { Archive Only; check all combinations }
  1303.   begin
  1304.     BC := clSilver;
  1305.     HC := clWhite;
  1306.     SC := clGray;
  1307.     TC := clBlack;
  1308.     if AmHidden then
  1309.     begin
  1310.       if AmReadOnly then
  1311.       begin
  1312.         if AmSystem then
  1313.         begin { Hid,RO,Sys }
  1314.           BC := clRed;
  1315.           HC := clLime;
  1316.           SC := clPurple;
  1317.           TC := clBlack;
  1318.         end
  1319.         else
  1320.         begin { RO,Hid }
  1321.           BC := clLime;
  1322.           HC := clFuchsia;
  1323.           SC := clMaroon;
  1324.           TC := clBlack;
  1325.         end;
  1326.       end
  1327.       else
  1328.       begin { Hid }
  1329.         BC := clFuchsia;
  1330.         HC := clWhite;
  1331.         SC := clPurple;
  1332.         TC := clBlack;
  1333.       end;
  1334.     end
  1335.     else
  1336.     begin
  1337.       if AmReadOnly then
  1338.       begin
  1339.         if AmSystem then
  1340.         begin { RO,Sys }
  1341.           BC := clRed;
  1342.           HC := clLime;
  1343.           SC := clMaroon;
  1344.           TC := clBlack;
  1345.         end
  1346.         else
  1347.         begin { RO }
  1348.           BC := clLime;
  1349.           HC := clWhite;
  1350.           SC := clGreen;
  1351.           TC := clBlack;
  1352.         end;
  1353.       end
  1354.       else
  1355.       begin
  1356.         if AmSystem then
  1357.         begin { System }
  1358.           BC := clRed;
  1359.           HC := clWhite;
  1360.           SC := clMaroon;
  1361.           TC := clBlack;
  1362.         end;
  1363.       end;
  1364.     end;
  1365.   end;
  1366. end;
  1367.  
  1368. { This procedure gets all icons for an given directory, including drives and }
  1369. { standard subdirectories. It does not get special combinations or h/ro/sys  }
  1370. procedure TFileIconPanelScrollbox.GetIconsForEntireDirectory(
  1371.             TargetPath  : String );
  1372. var Finished        : Boolean;         { Loop flag              }
  1373.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  1374.     TheResult       : Integer;         { return variable        }
  1375.     TempPath        : String;          { path for FF/FN         }
  1376.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  1377.     RowCounter    ,                    { position in row of FIP }
  1378.     ColumnCounter   : Integer;         { position in col of FIP }
  1379.     ButtonColor   ,                    { main panel color       }
  1380.     ButtonHLColor ,                    { bright panel color     }
  1381.     ButtonSColor  ,                    { dark panel color       }
  1382.     Textcolor       : TColor;          { label text color       }
  1383.     IsADir ,                           { Variable for file attr }
  1384.     IsAnArchive ,
  1385.     IsAVolumeID,
  1386.     IsAReadOnlyFile,
  1387.     IsAHiddenFile ,
  1388.     IsASystemFile     : Boolean;
  1389.     MaxTextLength     : Integer;       { Used to safely set size}
  1390. begin
  1391.   { hide during refresh }
  1392.   Visible := false;
  1393.   { Delete the current set, if any }
  1394.   ClearTheFIPs;
  1395.   { Get the icon sizes }
  1396.   TheFIP := TFileIconPanel.Create( Self );
  1397.   TheFIP.Parent := Self;
  1398.   TheFIP.FTheLabel.Canvas.Font.Name := 'MS Serif';
  1399.   TheFIP.FTheLabel.Canvas.Font.Size := 7;
  1400.   MaxTextLength := TheFIP.FTheLabel.Canvas.TextWidth( 'COMMAND.COM' );
  1401.   TheFIP.Free;
  1402.   TheIconSize := MaxTextLength + 13;
  1403.   TheIconSpacing := TheIconSize + 5;
  1404.   { Set up maximum icons per row based on screen size }
  1405.   MaxIconsInARow := ( Screen.Width div TheIconSpacing );
  1406.   { Set up the position counters }
  1407.   RowCounter := 1;
  1408.   ColumnCounter := 1;
  1409.   { Get the drives for the current machine }
  1410.   AddDriveIcons( ColumnCounter , RowCounter  );
  1411.   { Set up the initial variables }
  1412.   Finished := false;
  1413.   TempPath := TargetPath + '*.*';
  1414.   { Make the call to FindFirst set to get any file; will return '.' }
  1415.   { so discard it.                                                  }
  1416.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  1417.   { loop through all files in the directory and look for directories }
  1418.   while not Finished do
  1419.   begin
  1420.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1421.     TheResult := FindNext( TheSR );
  1422.     { A -1 result means no more files so exit }
  1423.     if TheResult <> 0 then finished := true else
  1424.     begin
  1425.       { Otherwise check for a directory attribute }
  1426.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  1427.        faDirectory ) then
  1428.       begin
  1429.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1430.          ButtonHLColor , ButtonSColor , TextColor );
  1431.         { If found create a new FileIconPanel on the imported scrollbox }
  1432.         { Note sending 0 ExtraData parameter to indicate file not drive }
  1433.         TheFIP := TFileIconPanel.Create( Self );
  1434.         TheFIP.Parent := Self;
  1435.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  1436.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize ,
  1437.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  1438.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  1439.         { Increment column counter and move to new row if past limit }
  1440.         ColumnCounter := ColumnCounter + 1;
  1441.         if ColumnCounter > MaxIconsInARow then
  1442.         begin
  1443.           ColumnCounter := 1;
  1444.           RowCounter := RowCounter + 1;
  1445.         end;
  1446.       end;
  1447.     end;
  1448.   end;
  1449.   { Set up new initialization variables }
  1450.   Finished := false;
  1451.   TempPath := TargetPath + '*.*';
  1452.   { Make needed call to FindFirst and discard '.' }
  1453.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  1454.   while not Finished do
  1455.   begin
  1456.     { Loop through file again, this time getting only archive files }
  1457.     TheResult := FindNext( TheSR );
  1458.     { Result of -1 indicates no more files }
  1459.     if TheResult <> 0 then Finished := true else
  1460.     begin
  1461.       { If faArchive file then add new FileIconPanel }
  1462.       TheFWB.GetFileAttributes(( Targetpath + TheSR.Name ) , IsADir ,
  1463.        IsAnArchive , IsAVolumeId , IsAHiddenFile , IsAReadOnlyFile ,
  1464.         IsASystemFile );
  1465.       if (( IsAnArchive ) and ( not IsADir )) then
  1466.       begin
  1467.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1468.          ButtonHLColor , ButtonSColor , TextColor );
  1469.         { Initialize new FileIconPanel and call initialize, sending 0 ED }
  1470.         TheFIP := TFileIconPanel.Create( Self );
  1471.         TheFIP.Parent := Self;
  1472.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  1473.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize ,
  1474.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  1475.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  1476.         { Increment column counter and if needed row counter }
  1477.         ColumnCounter := ColumnCounter + 1;
  1478.         if ColumnCounter > MaxIconsInARow then
  1479.         begin
  1480.           ColumnCounter := 1;
  1481.           RowCounter := RowCounter + 1;
  1482.         end;
  1483.       end;
  1484.     end;
  1485.   end;
  1486.   { Reset to visible }
  1487.   Visible := true;
  1488. end;
  1489.  
  1490. { Update method for FIPscrollbox }
  1491. procedure TFileIconPanelScrollBox.Update;
  1492. begin
  1493.   IconsNeedRefreshing := true;
  1494.   { Force a repaint }
  1495.   InvalidateRect( TheStoredHandle , nil , true );
  1496. end;
  1497.  
  1498. { Create method for FIPScrollbox }
  1499. constructor TFileIconPanelScrollBox.Create( AOwner : TComponent );
  1500. begin
  1501.   inherited Create( AOwner );
  1502.   TheFWB := TFileWorkBench.Create( Self );
  1503. end;
  1504.  
  1505. { This function returns the next selected file's name }
  1506. function TFileIconPanelScrollBox.GetNextSelection( SourceDirectory : String;
  1507.                            var CurrentItem : Integer ) : String;
  1508. var TheResult    : String;      { Holds result of function }
  1509.     TheComponent : TComponent;  { Used for typecast        }
  1510.     finished     : boolean;     { Loop control variable    }
  1511.     TheComponentCount : Integer;
  1512. begin
  1513.   TheComponentCount := ComponentCount;
  1514.   { If past end of components exit with no result }
  1515.   if CurrentItem > TheComponentCount then TheResult := '' else
  1516.   begin
  1517.     { Set loop counter and run till find match or run out }
  1518.     finished := false;
  1519.     while not finished do
  1520.     begin
  1521.       { Pull component out of the list and check it }
  1522.       TheComponent := Components[ CurrentItem - 1 ];
  1523.       { Increment counter for later }
  1524.       CurrentItem := CurrentItem + 1;
  1525.       { Do the typecast with AS }
  1526.       with TheComponent as TFileIconPanel do
  1527.       begin
  1528.         { If its selected make sure OK }
  1529.         if Selected then
  1530.         begin
  1531.           { Don't accept backup for this level of operation }
  1532.           if FTheLabel.Caption <> '..' then
  1533.           begin
  1534.             { Otherwise return the name and abort the loop }
  1535.             TheResult := FTheName;
  1536.             finished := true;
  1537.           end;
  1538.         end
  1539.         else
  1540.         begin
  1541.           { Check to see if out of components }
  1542.           if CurrentItem > TheComponentCount then
  1543.           begin
  1544.             { If so signal error and abort }
  1545.             TheResult := '';
  1546.             finished := true;
  1547.           end;
  1548.         end;
  1549.       end;
  1550.     end;
  1551.   end;
  1552.   GetNextSelection := TheResult;
  1553. end;
  1554.  
  1555. { This procedure places a selection of files in the display based on wildcards }
  1556. procedure TFileIconPanelScrollBox.DisplayRecursiveSearchResults(
  1557.            TheStartingDirectory : String );
  1558. var XCounter ,
  1559.     YCounter   : Integer;
  1560.  
  1561. { This procedure does a recursive file search by first getting all matches (in-}
  1562. { cluding directories) and adding them to the list. Then it checks for ALL the }
  1563. { subdirectories and does the same trick on them til there are no more matches }
  1564. { and no more subdirectories, at which point it exits and recurses back up.    }
  1565. procedure RecursiveFileSearch( TheWorkingDirectory : String; var XCounter ,
  1566.                                YCounter : Integer );
  1567.  
  1568. { VITAL!!! These variables MUST be local for recursrion to work! }
  1569. var
  1570.     Finished        : Boolean;         { Loop flag              }
  1571.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  1572.     TheResult       : Integer;         { return variable        }
  1573.     TargetPath ,
  1574.     FileMask   ,
  1575.     TheStoredWorkingDirectory ,
  1576.     ModifiedDirectory  : String;       { path for FF/FN         }
  1577.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  1578.     ButtonColor   ,                    { main panel color       }
  1579.     ButtonHLColor ,                    { bright panel color     }
  1580.     ButtonSColor  ,                    { dark panel color       }
  1581.     Textcolor       : TColor;          { label text color       }
  1582.  
  1583. begin
  1584.   { Set up the initial variables }
  1585.   Finished := false;
  1586.   TheStoredWorkingDirectory := TheWorkingDirectory;
  1587.   Targetpath := ExtractFilePath( TheWorkingDirectory );
  1588.   FileMask := ExtractFileName( TheWorkingDirectory );
  1589.   { Make the call to FindFirst set to get any file }
  1590.   TheResult := FindFirst( TheWorkingDirectory , faAnyFile , TheSR );
  1591.   if TheResult <> 0 then finished := true;
  1592.   if (( TheSr.Name <> '.' ) and ( TheSr.Name <> '..' ) and ( TheResult >= 0 ))
  1593.   then begin
  1594.     if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  1595.      faDirectory ) then
  1596.     begin { A directory }
  1597.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1598.        ButtonHLColor , ButtonSColor , TextColor );
  1599.       { If found create a new FileIconPanel on the imported scrollbox }
  1600.       { Note sending 0 ExtraData parameter to indicate file not drive }
  1601.       TheFIP := TFileIconPanel.Create( Self );
  1602.       TheFIP.Parent := Self;
  1603.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  1604.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  1605.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  1606.          + TheSr.Name , 'MS Serif' , [] , 0 );
  1607.       { Increment column counter and move to new row if past limit }
  1608.       XCounter := XCounter + 1;
  1609.       if XCounter > MaxIconsInARow then
  1610.       begin
  1611.         XCounter := 1;
  1612.         YCounter := YCounter + 1;
  1613.       end;
  1614.     end
  1615.     else
  1616.     begin { A File }
  1617.       { Set up the default color scheme for files }
  1618.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1619.        ButtonHLColor , ButtonSColor , TextColor );
  1620.       { If found create a new FileIconPanel on the imported scrollbox }
  1621.       { Note sending 0 ExtraData parameter to indicate file not drive }
  1622.       TheFIP := TFileIconPanel.Create( Self );
  1623.       TheFIP.Parent := Self;
  1624.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  1625.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize , 3 ,
  1626.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  1627.          + TheSr.Name , 'MS Serif' , [] , 0 );
  1628.       { Increment column counter and move to new row if past limit }
  1629.       XCounter := XCounter + 1;
  1630.       if XCounter > MaxIconsInARow then
  1631.       begin
  1632.         XCounter := 1;
  1633.         YCounter := YCounter + 1;
  1634.       end;
  1635.     end;
  1636.   end;
  1637.   { loop through all files in the directory and look for matches }
  1638.   while not Finished do
  1639.   begin
  1640.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1641.     TheResult := FindNext( TheSR );
  1642.     { A -1 result means no more files so exit }
  1643.     if TheResult <> 0 then finished := true else
  1644.     begin
  1645.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  1646.        faDirectory ) then
  1647.       begin { A directory }
  1648.         { Set up the blue color scheme for directories }
  1649.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1650.          ButtonHLColor , ButtonSColor , TextColor );
  1651.         { If found create a new FileIconPanel on the imported scrollbox }
  1652.         { Note sending 0 ExtraData parameter to indicate file not drive }
  1653.         TheFIP := TFileIconPanel.Create( Self );
  1654.         TheFIP.Parent := Self;
  1655.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  1656.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  1657.            7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  1658.             TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  1659.         { Increment column counter and move to new row if past limit }
  1660.         XCounter := XCounter + 1;
  1661.         if XCounter > MaxIconsInARow then
  1662.         begin
  1663.           XCounter := 1;
  1664.           YCounter := YCounter + 1;
  1665.         end;
  1666.       end
  1667.       else
  1668.       begin { A File }
  1669.         { Set up the default color scheme for files }
  1670.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1671.          ButtonHLColor , ButtonSColor , TextColor );
  1672.         { If found create a new FileIconPanel on the imported scrollbox }
  1673.         { Note sending 0 ExtraData parameter to indicate file not drive }
  1674.         TheFIP := TFileIconPanel.Create( Self );
  1675.         TheFIP.Parent := Self;
  1676.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  1677.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  1678.           7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  1679.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  1680.         { Increment column counter and move to new row if past limit }
  1681.         XCounter := XCounter + 1;
  1682.         if XCounter > MaxIconsInARow then
  1683.         begin
  1684.           XCounter := 1;
  1685.           YCounter := YCounter + 1;
  1686.         end;
  1687.       end;
  1688.     end;
  1689.   end;
  1690.   { Set up the variables to do recursive calls on all directories}
  1691.   Finished := false;
  1692.   ModifiedDirectory := ExtractFilePath( TheWorkingdirectory ) + '*.*';
  1693.   { Make the call to FindFirst set to get any file, ignore result }
  1694.   TheResult := FindFirst( ModifiedDirectory , faDirectory , TheSR );
  1695.   while not Finished do
  1696.   begin
  1697.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1698.     TheResult := FindNext( TheSR );
  1699.     { A -1 result means no more files so exit }
  1700.     if TheResult <> 0 then finished := true
  1701.     else
  1702.     begin
  1703.       if TheSR.Name <> '..' then { Ignore backup in this case }
  1704.       begin
  1705.         { Do second check due to bug in FindNext }
  1706.         if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  1707.         = faDirectory ) then
  1708.         begin
  1709.           { Set up modified directory to recurse into }
  1710.           ModifiedDirectory := ExtractFilePath( TheStoredWorkingDirectory ) +
  1711.            TheSR.Name + '\' + FileMask;
  1712.           { Perform the recursion }
  1713.           RecursiveFileSearch( ModifiedDirectory , XCounter , YCounter );
  1714.         end;
  1715.       end;
  1716.     end;
  1717.   end;
  1718. end;
  1719.  
  1720. begin
  1721.   { Keep the scrollbox from updating during refresh }
  1722.   Visible := false;
  1723.   { Make the clear call }
  1724.   ClearTheFIPs;
  1725.   XCounter := 1;
  1726.   YCounter := 1;
  1727.   { Get the drives for the current machine }
  1728.   AddDriveIcons( XCounter , YCounter );
  1729.   RecursiveFileSearch( TheStartingDirectory , XCounter , YCounter );
  1730.   { Make the scrollbox visible again }
  1731.   Visible := true;
  1732. end;
  1733.  
  1734. end.
  1735.